package com.sh.data.engine.domain.normalization.standard.model.enums;

import com.sh.data.engine.domain.common.model.domain.KeyValueDomain;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author boyue.wjl
 */
public enum UnitMeasureEnum {
    METRE("m", "米"),
    METRE_SQUARE("㎡", "平方米"),
    N_M("N·m", "牛·米"),
    CENTIGRADE("℃", "摄氏度"),
    YUAN("元", "元"),
    TEN_THOUSAND_YUAN("万元", "万元"),
    MILLION_YUAN("百万元", "百万元"),
    KILOGRAM("kg", "千克"),
    WATT("W", "瓦"),
    SECOND("s", "秒"),
    DAY("d", "天"),
    MINUTE("min", "分"),
    ROUND_PER_MINUTE("r/min", "转每分"),
    ;

    private String val;
    private String des;

    private UnitMeasureEnum(String val, String des) {
        this.val = val;
        this.des = des;
    }

    public static List<KeyValueDomain> getKeyValueList() {
        List<KeyValueDomain> resultList = new ArrayList<>();
        for (UnitMeasureEnum unitMeasureEnum : values()) {
            KeyValueDomain domain = new KeyValueDomain();
            domain.setKey(unitMeasureEnum.getVal());
            domain.setValue(unitMeasureEnum.getDes());
            resultList.add(domain);
        }
        return resultList;
    }

    public static UnitMeasureEnum valueOfDes(String des) {
        for (UnitMeasureEnum unitMeasureEnum : values()) {
            if (Objects.equals(unitMeasureEnum.getDes(), des)) {
                return unitMeasureEnum;
            }
        }
        return null;
    }

    public static String toStringByVal(String val) {
        if (StringUtils.isBlank(val)) {
            return "";
        }
        for (UnitMeasureEnum unitMeasureEnum : values()) {
            if (Objects.equals(unitMeasureEnum.getVal(), val)) {
                return unitMeasureEnum.getDes() + "(" + unitMeasureEnum.getVal() + ")";
            }
        }
        return "";
    }

    public String getVal() {
        return val;
    }

    public String getDes() {
        return des;
    }
}
